﻿using System;
using System.Collections.Generic;

namespace Layers.History
{
    public enum SeekPos
    {
        BeforeFirst = -1,
        First = 0,
        Current = 1,
        Last = 2,
        AfterLast = 3
    }

    public interface ICursor
    {
        object Current { get; set; }

        void Insert();

        void Remove();
    }

    /// <summary>
    /// Initially cursor is placed before first element of collection
    /// </summary>
    /// <typeparam name="E"></typeparam>
    public interface ICursor<E> : IEnumerator<E>, ICursor
    {
        /// <summary>
        /// read or write value to the collection
        /// </summary>
        E Current { get; set; }

        /// <summary>
        /// advances cursor to next position
        /// </summary>
        bool MoveNext();

        /// <summary>
        /// inserts new element before current element
        /// see table:
        /// current              result
        ///  pre-first, first       inserts at the beginning of coll
        ///  some                   inserts before some
        ///  last                   inserts before last
        ///  after-last             inserts at the end of coll
        /// </summary>
        void Insert();


        /// <summary>
        /// removes element under cursor
        /// </summary>
        void Remove();

        /// <summary>
        /// resets cursor to the position before first element
        /// </summary>
        void Reset();

        /// <summary>
        /// Seeks to "offset" from SeekPos.
        /// </summary>
        /// <param name="sp">Start position of seek</param>
        /// <param name="offset">Offset to add ot start position</param>
        /// <returns>index in the collection where element was inserted</returns>
        int Seek(SeekPos sp, int offset);
    }

    public interface IHistCursor<K, E> : ICursor<E>
    {
        K CurrentStamp { get; set; }
    }

    
    public interface IHistory<K, E> : IEnumerable<E>
    {
        int Count { get; }
        
        Window<K> Range { get; }

        IList<Window<K>> Windows { get; }

        IHistCursor<K, E> GetCursor();
    }

    public interface ITimeHistory<E> : IHistory<DateTime, E>
    {
    }
    
}